﻿@model Silvia.Models.Admin.TeamMgtModel
@{
    ViewBag.Title = "夕薇雅化妆工作室 - 团队管理";
    Model.Caption = "团队管理";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
<div class="system_toolbar">
    <input type="button" id="btnNew" value="新增" />
    <input type="button" id="btnModify" value="修改" />
    <input type="button" id="btnDelete" value="删除" />
</div>    
@{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.AppendLine(string.Format("var data={{Total:{0},",Model.List.Count));
    sb.AppendLine("Rows:[");
    for(int i =0;i < Model.List.Count;i++)
    {
        var item = Model.List[i];
        if(i == 0)
        {
            sb.Append("{");
        }
        else
        {
            sb.Append(",{");
        }
        sb.Append(string.Format("ID:'{0}',", item.Id));
        sb.Append(string.Format("Name:'{0}',", item.Name));
        sb.Append(string.Format("Introduction:'{0}',", item.Introduction));
        sb.Append(string.Format("ImageLink:'{0}',", item.ImageLink));
        sb.Append(string.Format("Seq:'{0}'", item.Seq));
        sb.Append("}");
    }
    sb.AppendLine("]};");
    string data = sb.ToString();
}
<script type="text/javascript">
    @Html.Raw(data)
    
    var menu = $.ligerMenu({ top: 100, left: 100, width: 120, items:
            [
            { text: '新增', click: newclick },
            { line: true },
            { text: '修改', click: modifyclick },
            { line: true },
            { text: '删除', click: deleteclick }
            ]
        });
    var grid;
    $(function () {

        grid = $("#maingrid").ligerGrid({
            columns: [
                { display: '名称', name: 'Name',width:120},
                { display: '名称', name: 'Introduction',width:200},
                { display: '图片', width:120,
                render: function (row)                {                    var html = "<img src='" + row.ImageLink + "' height=35 width=100/>";                    return html;                }},
                { display: '顺序', name: 'Seq',width:80 }],
                isScroll: false, data: data,pageSize:30,alternatingRow:true,  rowHeight:40,
                onContextmenu: function (node, e) {
            actionNodeID = node;
            menu.show({ top: e.pageY, left: e.pageX });
            return false;
                }
        });
        resetGridHeight(grid);
        $(window).resize(function () {
                resetGridHeight(grid);
            });
    });    function newclick(item, i) {
        var path = "/Admin/TeamEdit";
        window.location.href=path;
    }
    function modifyclick(item, i) {
        var path = "/Admin/TeamEdit?id="+actionNodeID.data.ID;
        window.location.href=path;
    }    function deleteclick(item, i) {
        del(actionNodeID.data.ID,actionNodeID.data.Name);
    }
    $(document).ready(function () {
        $("#btnNew").ligerButton(
        {
            click: function () {
                window.location.href = "/Admin/TeamEdit";
            }
        });
        $("#btnModify").ligerButton(
        {
            click: function () {
                var row = grid.getSelectedRow();
                if(row != null)
                {
                    var path = "/Admin/TeamEdit?id="+row.ID;
                    window.location.href=path;
                }
            }
        });

        $("#btnDelete").ligerButton(
        {
            click: function () {
                var row = grid.getSelectedRow();
                if(row != null)
                {
                    del(row.ID,row.Name);
                }
            }
        });
    });
</script>

<script type="text/javascript">
    function del(id, qq) {
        var msg = "确定删除团队成员:" + qq + "？";
        var result = confirm(msg);
        if (result == true)
            window.location.href = "/Admin/TeamDelete?id=" + id;
    }
</script>
 <div id="maingrid"></div>
